home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8246 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.9 KB  |  128 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.dcs.warwick.ac.uk!not-for-mail
  3. From: D.C.Molero@dcs.warwick.ac.uk (Daniel Castillo Molero)
  4. Subject: separate compilation
  5. X-Nntp-Posting-Host: angel
  6. Message-ID: <1996Mar2.164559.24931@dcs.warwick.ac.uk>
  7. Sender: news@dcs.warwick.ac.uk (Network News)
  8. Organization: Department of Computer Science, Warwick University, England
  9. Date: Sat, 2 Mar 1996 16:45:59 GMT
  10.  
  11.  
  12. Hello,
  13. thank you for looking at this message.
  14. My problem is the following:
  15. I had a program which creates a linked list and then prints it, and was
  16. working, but when I tried to separate it in 3 different files, and compile
  17. it using  
  18.            gcc file1.c file2.c file3.c
  19.  
  20. it doesn't compile.
  21.  
  22.  
  23. file1.c
  24. -------
  25. /* this file is supposed to print the linked list pointed
  26.  to by first_side.
  27. */
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30.  
  31. /* declare the structure side as extern to avoid having to redeclare it,
  32.    since it is already declared in file2.c
  33. */
  34. extern struct side;
  35.  
  36. int main(void) {
  37. struct side *tmp;
  38. /* first_side is declared in file2.c and points to the first element
  39.    of the list.
  40. */
  41. extern struct side *first_side;
  42. /* print the three elements */
  43.  
  44.     for (tmp = first_side; tmp; tmp = tmp->next)
  45.         printf("side: %d\n", tmp->a);
  46.  
  47.     return 0;
  48. }
  49.  
  50.  
  51. file2.c
  52. -------
  53.  
  54. /* type of each element of the linked list */
  55. struct side {
  56.     int a;
  57.     struct side *next;
  58. };
  59.  
  60. void store_side(struct side* i, struct side** first_side);
  61.  
  62. void create_list(void)
  63. {
  64. struct side *i;
  65. struct side *first_side;
  66.  
  67.     /* insert first element */
  68.     first_side = 0;
  69.     i = malloc(1*sizeof(struct side));
  70.     i->a = 0;
  71.     store_side(i, &first_side);
  72.  
  73.     /* insert second element */
  74.     i = malloc(1*sizeof(struct side));
  75.     i->a = 1;
  76.     store_side(i, &first_side);
  77.  
  78.     /* insert third elemenet */
  79.     i = malloc(1*sizeof(struct side));
  80.     i->a = 2;
  81.     store_side(i, &first_side);
  82.  
  83. }
  84.  
  85.  
  86. file3.c
  87. -------
  88.  
  89. /* declare the structure side as extern, as in file1.c */
  90. extern struct side; 
  91.  
  92. /* insert a new element in the list */
  93. void
  94. store_side(struct side* i, struct side** first_side)
  95. {
  96.     i->next = *first_side;
  97.     *first_side = i;
  98. }
  99.  
  100. ------------------------------------
  101.  
  102. The errors that I get are the following
  103.  
  104. prnlist.c:4: warning: useless keyword or type name in empty declaration
  105. prnlist.c: In function `main':
  106. prnlist.c:11: dereferencing pointer to incomplete type
  107. prnlist.c:12: dereferencing pointer to incomplete type
  108. inselem.c:2: warning: useless keyword or type name in empty declaration
  109. inselem.c: In function `store_side':
  110. inselem.c:8: dereferencing pointer to incomplete type
  111. crlist.c: In function `create_list':
  112. crlist.c:17: warning: assignment makes pointer from integer without a cast
  113. crlist.c:22: warning: assignment makes pointer from integer without a cast
  114. crlist.c:27: warning: assignment makes pointer from integer without a cast
  115.  
  116.  
  117. -----------------
  118.  
  119. Thank you very much for any help.
  120. danny
  121.  
  122. danmol@dcs.warwick.ac.uk
  123.  
  124. -- 
  125. * Daniel Castillo.  D.C.Molero@dcs.warwick.ac.uk *
  126.  
  127.  
  128.